from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import (
    AnsibleConfigViewSet,
    AnsibleInventoryViewSet,
    AnsibleCredentialViewSet,
    AnsibleGlobalSettingViewSet,
    AnsibleStatsViewSet,
    AnsibleJobViewSet,
    AnsibleHostFileViewSet
)

router = DefaultRouter()
router.register(r'configs', AnsibleConfigViewSet)
router.register(r'inventories', AnsibleInventoryViewSet)
router.register(r'credentials', AnsibleCredentialViewSet)
router.register(r'settings', AnsibleGlobalSettingViewSet)
router.register(r'stats', AnsibleStatsViewSet, basename='ansible-stats')
router.register(r'jobs', AnsibleJobViewSet)

urlpatterns = [
    path('', include(router.urls)),
    # 主机文件管理API
    path('hosts/<int:host_id>/directories/', AnsibleHostFileViewSet.as_view({'get': 'get_host_directories'}), name='host-directories'),
    path('hosts/<int:host_id>/playbook-files/', AnsibleHostFileViewSet.as_view({'get': 'get_playbook_files'}), name='playbook-files'),
    path('hosts/<int:host_id>/playbook-content/', AnsibleHostFileViewSet.as_view({'get': 'get_playbook_content', 'post': 'save_playbook_content'}), name='playbook-content'),
]
